﻿using BaseUI;
using BLL;
using System;
using System.Collections;
using System.Data;

namespace Thksoft.BusinessExpansion.Process
{
    public partial class Process_Details : BasePage
    {
        private Sys_UserBLL sub = new Sys_UserBLL();

        private Lc_QueueBLL lqb = new Lc_QueueBLL();
        private Lc_NodeBLL lnb = new Lc_NodeBLL();
        private Lc_ConditionBLL lcb = new Lc_ConditionBLL();

        public static string ContentLable, LineContent;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LineContent = "";
                ContentLable = "";
                FlowNumber.Text = Request.QueryString["ID"].ToString();
                DataTable dtleft = new DataTable();
                dtleft.Columns.Add("N_QUEUE_ID_LEFT");
                dtleft.Columns.Add("N_CONDITION_STATE");
                dtleft.Columns.Add("N_QUEUE_NUMBER");
                //获得所属流程的所有左节点
                DataTable disleft = lqb.getconleft(Request.QueryString["ID"]);
                //获得节点的状态和执行顺序
                for (int i = 0; i < disleft.Rows.Count; i++)
                {
                    DataRow dr = dtleft.NewRow();
                    dr[0] = disleft.Rows[i][0].ToString();
                    dr[1] = lqb.getContionState(disleft.Rows[i][0].ToString());
                    dr[2] = lqb.getQueueNumber(disleft.Rows[i][0].ToString());
                    dtleft.Rows.Add(dr);
                }

                DataTable dtright = new DataTable();
                dtright.Columns.Add("N_QUEUE_ID_RIGHT");
                dtright.Columns.Add("N_CONDITION_STATE");
                dtright.Columns.Add("N_QUEUE_NUMBER");
                //获得所属流程的右节点，并且没有相同的左节点
                DataTable disright = lqb.getconright(Request.QueryString["ID"]);
                for (int i = 0; i < disright.Rows.Count; i++)
                {
                    DataRow dr = dtright.NewRow();
                    dr[0] = disright.Rows[i][0].ToString();
                    dr[1] = lqb.GetContionStateRight(disright.Rows[i][0].ToString());
                    dr[2] = lqb.getQueueNumber(disright.Rows[i][0].ToString());
                    dtright.Rows.Add(dr);
                }

                //查询所属流程的逻辑表，并且状态不能为0
                DataTable con = lqb.getcon(Request.QueryString["ID"].ToString());
                //判断是否有增加
                if (Session["xndt"] != null)
                {
                    if ((Session["xndt"] as DataTable).Rows.Count > 0)
                    {
                        xndt = Session["xndt"] as DataTable;
                        xnqueue = Session["xnqueue"] as DataTable;
                        xndnode = Session["xndnode"] as DataTable;
                        for (int i = 0; i < xndt.Rows.Count; i++)
                        {
                            //判断是否是当前流程
                            if (xndt.Rows[i][2].ToString().Equals(Request.QueryString["ID"].ToString()))
                            {
                                bool left = false;
                                bool right = false;
                                bool leftright = false;
                                bool rightleft = false;
                                for (int g = 0; g < dtright.Rows.Count; g++)
                                {
                                    //判断添加队列是否与右节点重复
                                    if (xndt.Rows[i][3].ToString().Equals(dtright.Rows[g][0].ToString()))
                                    {
                                        dtright.Rows.Remove(dtright.Rows[g]);
                                        // rightleft = true;
                                        //  left = true;
                                        break;
                                    }
                                }
                                //判断添加队列是否与左节点重复
                                if (rightleft)
                                {
                                    for (int j = 0; j < dtleft.Rows.Count; j++)
                                    {
                                        if (xndt.Rows[i][3].ToString().Equals(dtleft.Rows[j][0].ToString()))
                                        {
                                            rightleft = true;
                                            left = true;
                                        }
                                    }
                                }
                                if (left)
                                {
                                    DataRow dr = dtleft.NewRow();
                                    dr[0] = xndt.Rows[i][3].ToString();
                                    dr[1] = xndt.Rows[i][5].ToString();
                                    for (int k = 0; k < xnqueue.Rows.Count; k++)
                                    {
                                        if (xndt.Rows[i][3].ToString().Equals(xnqueue.Rows[k][0].ToString()))
                                        {
                                            dr[2] = xnqueue.Rows[k][3].ToString();
                                            break;
                                        }
                                    }

                                    dtleft.Rows.Add(dr);
                                }
                                for (int f = 0; f < dtleft.Rows.Count; f++)
                                {
                                    if (xndt.Rows[i][4].ToString().Equals(dtleft.Rows[f][0].ToString()))
                                    {
                                        leftright = true;
                                        right = true;
                                        break;
                                    }
                                }
                                if (leftright)
                                {
                                    for (int r = 0; r < dtright.Rows.Count; r++)
                                    {
                                        if (xndt.Rows[i][4].ToString().Equals(dtright.Rows[r][0].ToString()))
                                        {
                                            right = true;
                                            break;
                                        }
                                    }
                                }

                                if (right)
                                {
                                    DataRow dr = dtright.NewRow();
                                    dr[0] = xndt.Rows[i][4].ToString();
                                    dr[1] = xndt.Rows[i][5].ToString();
                                    for (int k = 0; k < xnqueue.Rows.Count; k++)
                                    {
                                        if (xndt.Rows[i][4].ToString().Equals(xnqueue.Rows[k][0].ToString()) || xndt.Rows[i][3].ToString().Equals(xnqueue.Rows[k][0].ToString()))
                                        {
                                            dr[2] = xnqueue.Rows[k][3].ToString();
                                            break;
                                        }
                                    }

                                    dtright.Rows.Add(dr.ItemArray);
                                }
                                //把添加的逻辑表放在查询的逻辑表中
                                con.Rows.Add(xndt.Rows[i].ItemArray);
                            }
                        }
                    }
                }
                //修改状态，左节点不会为结束状态
                for (int i = 0; i < dtleft.Rows.Count; i++)
                {
                    bool isnode = true;
                    if (dtleft.Rows[i][1].ToString() == "3" || dtleft.Rows[i][1].ToString() == "1")
                    {
                        for (int j = 0; j < con.Rows.Count; j++)
                        {
                            if (dtleft.Rows[i][0].ToString() == con.Rows[j][4].ToString())
                            {
                                isnode = false;
                                break;
                            }
                        }
                        if (isnode)
                        {
                            dtleft.Rows[i][1] = "1";
                        }
                        else
                        {
                            dtleft.Rows[i][1] = "2";
                        }
                    }
                }
                //修改状态不能为开始
                for (int i = 0; i < dtright.Rows.Count; i++)
                {
                    bool isnode = true;
                    if (dtright.Rows[i][1].ToString() == "2" || dtright.Rows[i][1].ToString() == "1")
                    {
                        for (int j = 0; j < con.Rows.Count; j++)
                        {
                            if (dtright.Rows[i][0].ToString() == con.Rows[j][3].ToString())
                            {
                                isnode = false;
                                break;
                            }
                        }
                        if (isnode)
                        {
                            dtright.Rows[i][1] = "1";
                        }
                        else
                        {
                            dtright.Rows[i][1] = "3";
                        }
                    }
                }
                //查看是否有执行顺序为空的
                for (int z = 0; z < dtleft.Rows.Count; z++)
                {
                    if (string.IsNullOrEmpty(dtleft.Rows[z]["N_QUEUE_NUMBER"].ToString()))
                    {
                        dtleft.Rows[z]["N_QUEUE_NUMBER"] = lqb.getQueueNumber(dtleft.Rows[z][0].ToString());
                    }
                }
                //使用冒泡排序
                dtleft = maopao(dtleft);

                //dt表结构
                DataTable dqueue = null;
                DataTable dqueuer = null;
                int i1 = 20;
                int i2 = 100;
                int i3 = 100;
                if (dtleft.Rows.Count > 0)
                {
                    for (int i = 0; i < dtleft.Rows.Count + dtright.Rows.Count; i++)
                    {
                        //生成的方块偏左
                        int xleft = 350;
                        //生成的方块高度+60
                        int xtop = i1;
                        //生成工作流节点块
                        int jieshuTop = i2;
                        int kaishiTop = i3;
                        DataTable dnode = null;
                        DataTable dnoder = null;
                        //执行左节点，生成模块
                        if (i <= dtleft.Rows.Count - 1)
                        {
                            dqueue = lqb.getqueue(dtleft.Rows[i][0].ToString(), Request.QueryString["ID"].ToString());

                            if (dqueue.Rows.Count <= 0)
                            {
                                isnulld(con, dqueue, dqueuer, 0, i, xnqueue, dtleft);
                            }
                            dqueuer = lqb.getqueuer(dtleft.Rows[i][0].ToString(), Request.QueryString["ID"].ToString());
                            if (dqueuer.Rows.Count <= 0)
                            {
                                isnulld3(con, dqueue, dqueuer, 0, i, xnqueue, dtleft);
                            }
                            dnode = lqb.getnode(dqueue.Rows[0]["N_NODE_ID"].ToString());
                            if (dnode.Rows.Count <= 0)
                            {
                                isnullnode(dnode, dqueue, xndnode);
                            }
                            if (dqueuer.Rows.Count > 0)
                            {
                                dnoder = lqb.getnode(dqueuer.Rows[0]["N_NODE_ID"].ToString());
                                if (dnoder.Rows.Count <= 0 || dnoder == null)
                                {
                                    isnullnode(dnoder, dqueuer, xndnode);
                                }
                            }
                        }
                        //执行右节点，生成模块
                        else
                        {
                            dqueue = lqb.getqueue(dtright.Rows[i - (dtleft.Rows.Count)][0].ToString(), Request.QueryString["ID"].ToString());
                            dqueuer = lqb.getqueuer(dtright.Rows[i - (dtleft.Rows.Count)][0].ToString(), Request.QueryString["ID"].ToString());
                            if (dqueue.Rows.Count <= 0)
                            {
                                isnulld(con, dqueue, dqueuer, 1, i - dtleft.Rows.Count, xnqueue, dtright);
                            }
                            if (dqueuer.Rows.Count <= 0)
                            {
                                isnulld3(con, dqueue, dqueuer, 1, i - (dtleft.Rows.Count), xnqueue, dtright);
                            }
                            if (dqueuer.Rows.Count <= 0)
                            {
                                if (xndt != null && xndt.Rows.Count > 0)
                                {
                                    isnulld2(xndt, dqueue, dqueuer, 1, i - (dtleft.Rows.Count), xnqueue, dtright);
                                }
                            }
                            dnode = lqb.getnode(dqueue.Rows[0]["N_NODE_ID"].ToString());
                            if (dnode.Rows.Count <= 0)
                            {
                                isnullnode(dnode, dqueue, xndnode);
                            }
                            if (dqueuer.Rows.Count > 0)
                            {
                                dnoder = lqb.getnode(dqueuer.Rows[0]["N_NODE_ID"].ToString());
                                if (dnoder.Rows.Count <= 0 || dnoder == null)
                                {
                                    isnullnode(dnoder, dqueuer, xndnode);
                                }
                            }
                        }

                        if (i == 0 && Session["xnqueue"] == null)
                        {
                            xndt = con.Clone();
                            //dqueue表结构
                            xnqueue = dqueue.Clone();
                            //dnode表结构
                            xndnode = dnode.Clone();
                            Session["xndt"] = xndt;
                            Session["xnqueue"] = xnqueue;
                            Session["xndnode"] = xndnode;
                        }

                        //审批方式
                        string shenpi = "";
                        string[] strs = null;
                        if (dqueuer.Rows.Count > 0)
                        {
                            if (dqueuer.Rows[0][5].ToString() == "0")
                            {
                                shenpi = "单人审核";
                            }
                            else if (dqueuer.Rows[0][5].ToString() == "1")
                            {
                                shenpi = "多人审核1人审核通过即通过";
                            }
                            else if (dqueuer.Rows[0][5].ToString() == "2")
                            {
                                shenpi = "多人审核全部通过才通过";
                            }
                            else if (dqueuer.Rows[0][5].ToString() == "3")
                            {
                                shenpi = "指定人员办理";
                            }
                            else if (dqueuer.Rows[0][5].ToString() == "4")
                            {
                                shenpi = "默认片区管理员";
                            }
                            else if (dqueuer.Rows[0][5].ToString() == "5")
                            {
                                shenpi = "特定操作关联";
                            }
                            strs = dqueuer.Rows[0][4].ToString().Split(',');
                        }
                        //办理人员
                        string banliren = "";
                        //当前节点
                        string NodeN = "";
                        //下一个节点
                        string NodeR = "";
                        if (strs != null && strs.Length > 0 && !string.IsNullOrEmpty(dqueuer.Rows[0][4].ToString()))
                        {
                            for (int k = 0; k < strs.Length; k++)
                            {
                                if (k < strs.Length - 1)
                                {
                                    banliren += sub.GetUserNameS(strs[k].ToString()) + ",";
                                }
                                else
                                {
                                    banliren += sub.GetUserNameS(strs[k].ToString());
                                }
                            }
                        }
                        if (string.IsNullOrEmpty(shenpi) && string.IsNullOrEmpty(banliren))
                        {
                            shenpi = "结束";
                            banliren = "结束";
                        }
                        if (dnode.Rows != null)
                        {
                            if (dnode.Rows.Count > 0)
                            {
                                NodeN = dnode.Rows[0][1].ToString();
                            }
                            else
                            {
                                NodeN = "结束";
                            }
                        }
                        else
                        {
                            NodeN = "结束";
                        }
                        if (dnoder != null)
                        {
                            if (dnoder.Rows.Count > 0)
                            {
                                NodeR = dnoder.Rows[0][1].ToString();
                            }
                            else
                            {
                                NodeR = "结束";
                            }
                        }
                        else
                        {
                            NodeR = "结束";
                        }
                        //办理时间
                        string sj = "";
                        if (dnoder != null)
                        {
                            if (dnoder.Rows.Count > 0)
                            {
                                sj = (Convert.ToInt32(dnoder.Rows[0][4].ToString()) * 24).ToString();
                            }
                        }
                        //状态2是开始3是结束1是中间
                        string zt = "";
                        if (i < dtleft.Rows.Count)
                        {
                            zt = dtleft.Rows[i]["N_CONDITION_STATE"].ToString();
                        }
                        else
                        {
                            zt = dtright.Rows[i - dtleft.Rows.Count]["N_CONDITION_STATE"].ToString();
                        }
                        //生成开始模块 title=\"下一步骤：" + NodeR + "&#13;&#10;--&#13;&#10;经办人姓名：" + banliren + "&#13;&#10;--&#13;&#10;审批人员选择：" + shenpi + "&#13;&#10;--&#13;&#10;评审模式：" + shenpi + "&#13;&#10;--&#13;&#10;当前节点，" + sj + "小时未审批自动结束\";
                        if (zt == "2")
                        {
                            ContentLable += "<vml:roundrect id=" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + " ondblclick=Edit_Process(" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + "); style=\"z-index: 1; left: 150px; vertical-align: middle; width: 100px; cursor: hand; position: absolute; top: " + kaishiTop + "px; height: 70px; text-align: center\"  coordsize=\"21600,21600\" arcsize=\"4321f\" fillcolor=\"#00EE00\" receiverName=\"\" receiverID=\"\" readOnly=\"0\" flowFlag=\"0\" flowTitle=\"<b>" + dqueue.Rows[0]["N_QUEUE_NUMBER"].ToString() + "</b><br>" + NodeN + "\" passCount=\"0\" flowType=\"start\" table_id=\"" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + "\" inset=\"2pt,2pt,2pt,2pt\"><vml:shadowoffset=\"3px,3px\" color=\"#b3b3b3\" type=\"single\" on=\"T\"></vml:shadow><vml:textbox onselectstart=\"return false;\" inset=\"1pt,2pt,1pt,1pt\"><B>" + dqueue.Rows[0]["N_QUEUE_NUMBER"].ToString() + "</B><BR>" + NodeN + "<BR><img src='../../Images/Under.png' height='30px'/></vml:textbox></vml:roundrect>";
                            i3 = i3 + 100;
                        }
                        //生成结束模块  title=\"下一步骤： 结束 &#13;&#10;--&#13;&#10;经办人姓名：&#13;&#10;--&#13;&#10;审批人员选择：" + shenpi + "&#13;&#10;--&#13;&#10;评审模式：" + shenpi + "&#13;&#10;--&#13;&#10;当前节点，" + sj + "小时未审批自动结束\";
                        else if (zt == "3")
                        {
                            ContentLable += "<vml:roundrect id=" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + " ondblclick=Edit_Process(" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + "); style=\"z-index: 1; left: 500px; vertical-align: middle; width: 100px; cursor: hand; position: absolute; top: " + jieshuTop + "px; height: 70px; text-align: center\"  coordsize=\"21600,21600\" arcsize=\"4321f\" fillcolor=\"#00EE00\" receiverName=\"\" receiverID=\"\" readOnly=\"0\" flowFlag=\"0\" flowTitle=\"<b>" + dqueue.Rows[0]["N_QUEUE_NUMBER"].ToString() + "</b><br>" + dnode.Rows[0][1].ToString() + "\" passCount=\"0\" flowType=\"start\" table_id=\"" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + "\" inset=\"2pt,2pt,2pt,2pt\"><vml:shadowoffset=\"3px,3px\" color=\"#b3b3b3\" type=\"single\" on=\"T\"></vml:shadow><vml:textbox onselectstart=\"return false;\" inset=\"1pt,2pt,1pt,1pt\"><B>" + dqueue.Rows[0]["N_QUEUE_NUMBER"].ToString() + "</B><BR>" + dnode.Rows[0][1].ToString() + "</vml:textbox></vml:roundrect>";
                            i2 = i2 + 100;
                        }
                        //生成中间模块 title=\"下一步骤：" + NodeR + "&#13;&#10;--&#13;&#10;经办人姓名：" + banliren + "&#13;&#10;--&#13;&#10;审批人员选择：" + shenpi + "&#13;&#10;--&#13;&#10;评审模式：" + shenpi + "&#13;&#10;--&#13;&#10;当前节点，" + sj + "小时未审批自动结束\";
                        else
                        {
                            //生成的方块高度+60
                            i1 = i1 + 100;
                            ContentLable += "<vml:roundrect id=" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + " ondblclick=Edit_Process(" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + "); style=\"z-index: 1; left: " + xleft.ToString() + "px; vertical-align: middle; width: 100px; cursor: hand; position: absolute; top: " + xtop.ToString() + "px; height: 70px; text-align: center\"  coordsize=\"21600,21600\" arcsize=\"4321f\" fillcolor=\"#eeeeee\" receiverName=\"\" receiverID=\"\" readOnly=\"0\" flowFlag=\"0\" flowTitle=\"<b>" + dqueue.Rows[0]["N_QUEUE_NUMBER"].ToString() + "</b><br>" + NodeN + "\" passCount=\"0\" flowType=\"\" table_id=\"" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + "\" inset=\"2pt,2pt,2pt,2pt\"><vml:shadowoffset=\"3px,3px\" color=\"#b3b3b3\" type=\"single\" on=\"T\"></vml:shadow><vml:textbox onselectstart=\"return false;\" inset=\"1pt,2pt,1pt,1pt\"><B>" + dqueue.Rows[0]["N_QUEUE_NUMBER"].ToString() + "</B><BR>" + NodeN + "</vml:textbox></vml:roundrect>";
                        }
                        //画箭头，不是结束
                        if (zt != "3" && i < dtleft.Rows.Count)
                        {
                            //查找是否有多个走向的
                            DataTable dis = con.Clone();
                            for (int h = 0; h < con.Rows.Count; h++)
                            {
                                if (con.Rows[h][3].ToString().Equals(dtleft.Rows[i][0].ToString()))
                                {
                                    dis.Rows.Add(con.Rows[h].ItemArray);
                                }
                            }

                            if (dis != null && dis.Rows.Count > 0)
                            {
                                for (int d = 0; d < dis.Rows.Count; d++)
                                {
                                    DataTable disr = lqb.getqueue(dis.Rows[d]["N_QUEUE_ID_RIGHT"].ToString(), Request.QueryString["ID"].ToString());
                                    if (disr.Rows.Count <= 0)
                                    {
                                        if (xnqueue != null && xnqueue.Rows.Count > 0)
                                        {
                                            for (int jk = 0; jk < xnqueue.Rows.Count; jk++)
                                            {
                                                if (dis.Rows[d]["N_QUEUE_ID_RIGHT"].ToString() == xnqueue.Rows[jk]["N_QUEUE_ID"].ToString())
                                                {
                                                    disr.Rows.Add(xnqueue.Rows[jk].ItemArray);
                                                }
                                            }
                                        }
                                    }
                                    //画箭头
                                    LineContent = LineContent + "<vml:line title=\"\" style=\"display: none; z-index: 2; position: absolute\" to=\"0,0\" from=\"0,0\" coordsize=\"21600,21600\" arcsize=\"4321f\" object=\"" + disr.Rows[0]["N_QUEUE_ID"].ToString() + "\" source=\"" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + "\" mfrID=\"" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + "\"><vml:stroke endarrow=\"block\"></vml:stroke><vml:shadow offset=\"1px,1px\" color=\"#b3b3b3\" type=\"single\" on=\"T\"></vml:shadow></vml:line>";
                                }
                            }
                            else
                            {
                                LineContent = LineContent + "<vml:line title=\"\" style=\"display: none; z-index: 2; position: absolute\" to=\"0,0\" from=\"0,0\" coordsize=\"21600,21600\" arcsize=\"4321f\" object=\"" + dqueuer.Rows[0]["N_QUEUE_ID"].ToString() + "\" source=\"" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + "\" mfrID=\"" + dqueue.Rows[0]["N_QUEUE_ID"].ToString() + "\"><vml:stroke endarrow=\"block\"></vml:stroke><vml:shadow offset=\"1px,1px\" color=\"#b3b3b3\" type=\"single\" on=\"T\"></vml:shadow></vml:line>";
                            }
                        }
                    }
                }
                //else
                //{
                //    decimal coid = lcb.Getnext();
                //    decimal quid = decimal.Parse(lqb.getNext());
                //    decimal quidr = decimal.Parse(lqb.getNext());
                //    decimal noid = decimal.Parse(lnb.getNext());
                //    decimal noidr = decimal.Parse(lnb.getNext());
                //    if (lcb.InsertConsqueue(coid, quid, quidr, noid, noidr, decimal.Parse(Request.QueryString["ID"].ToString()), lognUser.USER_ID, DateTime.Now))
                //    {
                //        Response.Redirect("Work_Process_Details.aspx?ID=" + Request.QueryString["ID"].ToString());
                //    }
                //}
            }
        }

        /// <summary>
        /// 查找用户添加的队列
        /// </summary>
        /// <param name="con"></param>
        /// <param name="dqueue"></param>
        /// <param name="dqueuer"></param>
        /// <param name="z"></param>
        /// <param name="index"></param>
        /// <param name="xnqueue"></param>
        /// <param name="dleft"></param>
        private void isnulld(DataTable con, DataTable dqueue, DataTable dqueuer, int z, int index, DataTable xnqueue, DataTable dleft)
        {
            if (dqueue.Rows.Count <= 0)
            {
                for (int i = 0; i < xnqueue.Rows.Count; i++)
                {
                    if (z == 0)
                    {
                        if (dleft.Rows[index]["N_QUEUE_ID_LEFT"].ToString() == xnqueue.Rows[i][0].ToString())
                        {
                            dqueue.Rows.Add(xnqueue.Rows[i].ItemArray);
                        }
                    }
                    else
                    {
                        if (dleft.Rows[index]["N_QUEUE_ID_RIGHT"].ToString() == xnqueue.Rows[i][0].ToString())
                        {
                            dqueue.Rows.Add(xnqueue.Rows[i].ItemArray);
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 查找用户添加的下一个队列
        /// </summary>
        /// <param name="con"></param>
        /// <param name="dqueue"></param>
        /// <param name="dqueuer"></param>
        /// <param name="z"></param>
        /// <param name="index"></param>
        /// <param name="xnqueue"></param>
        /// <param name="dleft"></param>
        private void isnulld2(DataTable con, DataTable dqueue, DataTable dqueuer, int z, int index, DataTable xnqueue, DataTable dleft)
        {
            if (dqueuer.Rows.Count <= 0 && index < con.Rows.Count)
            {
                for (int i = 0; i < dleft.Rows.Count; i++)
                {
                    if (con.Rows[index]["N_QUEUE_ID_LEFT"].ToString() == dleft.Rows[i][0].ToString())
                    {
                        for (int t = 0; t < xnqueue.Rows.Count; t++)
                        {
                            if (xnqueue.Rows[t][0].ToString() == con.Rows[index]["N_QUEUE_ID_RIGHT"].ToString())
                            {
                                dqueuer.Rows.Add(xnqueue.Rows[i].ItemArray);
                                break;
                            }
                        }
                        if (dqueuer.Rows.Count <= 0)
                        {
                            dqueuer.Rows.Add(lqb.getqueue(con.Rows[index]["N_QUEUE_ID_RIGHT"].ToString(), Request.QueryString["ID"].ToString()));
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 查找用户添加的下一个队列
        /// </summary>
        /// <param name="con"></param>
        /// <param name="dqueue"></param>
        /// <param name="dqueuer"></param>
        /// <param name="z"></param>
        /// <param name="index"></param>
        /// <param name="xnqueue"></param>
        /// <param name="dleft"></param>
        private void isnulld3(DataTable con, DataTable dqueue, DataTable dqueuer, int z, int index, DataTable xnqueue, DataTable dleft)
        {
            ArrayList rightnode = new ArrayList(53);
            if (dqueuer.Rows.Count <= 0)
            {
                for (int i = 0; i < con.Rows.Count; i++)
                {
                    if (z == 0)
                    {
                        if (dleft.Rows[index]["N_QUEUE_ID_LEFT"].ToString() == con.Rows[i][3].ToString())
                        {
                            rightnode.Add(con.Rows[i][4].ToString());
                        }
                    }
                    else
                    {
                        if (dleft.Rows[index]["N_QUEUE_ID_RIGHT"].ToString() == con.Rows[i][3].ToString())
                        {
                            rightnode.Add(con.Rows[i][4].ToString());
                        }
                    }
                }
                bool getr = true;
                bool getrr = true;
                int intr = 0;
                int intrr = 0;
                if (rightnode != null && rightnode.Count > 0 && xnqueue != null)
                {
                    for (int k = 0; k < rightnode.Count; k++)
                    {
                        for (int i = 0; i < xnqueue.Rows.Count; i++)
                        {
                            if (z == 0)
                            {
                                if (rightnode[k].ToString() != xnqueue.Rows[i][0].ToString())
                                {
                                    getr = false;
                                }
                                else
                                {
                                    getr = true;
                                    intr = i;
                                    break;
                                }
                            }
                            else
                            {
                                if (rightnode[k].ToString() != xnqueue.Rows[i][0].ToString())
                                {
                                    dqueuer.Rows.Add(lqb.getqueue(rightnode[k].ToString(), Request.QueryString["ID"].ToString()).Rows[0].ItemArray);
                                    getrr = false;
                                }
                                else
                                {
                                    getrr = true;
                                    intrr = i;
                                    break;
                                }
                            }
                        }
                        if (getr)
                        {
                            dqueuer.Rows.Add(xnqueue.Rows[intr].ItemArray);
                        }
                        else
                        {
                            dqueuer.Rows.Add(lqb.getqueue(rightnode[k].ToString(), Request.QueryString["ID"].ToString()).Rows[0].ItemArray);
                        }
                        if (getrr)
                        {
                            dqueuer.Rows.Add(xnqueue.Rows[intrr].ItemArray);
                        }
                        else
                        {
                            dqueuer.Rows.Add(lqb.getqueue(rightnode[k].ToString(), Request.QueryString["ID"].ToString()).Rows[0].ItemArray);
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 查找用户添加的节点
        /// </summary>
        /// <param name="node"></param>
        /// <param name="dqueue"></param>
        /// <param name="xnnode"></param>
        private void isnullnode(DataTable node, DataTable dqueue, DataTable xnnode)
        {
            for (int i = 0; i < xnnode.Rows.Count; i++)
            {
                if (xnnode.Rows[i][0].ToString().Equals(dqueue.Rows[0]["N_NODE_ID"].ToString()))
                {
                    node.Rows.Add(xnnode.Rows[i].ItemArray);
                }
            }
        }

        private DataTable xndt = null;
        private DataTable xnqueue = null;
        private DataTable xndnode = null;

        /// <summary>
        /// 查找用户添加的节点的下一个
        /// </summary>
        /// <param name="noder"></param>
        /// <param name="dqueuer"></param>
        /// <param name="xnnode"></param>
        private void isnullnode2(DataTable noder, DataTable dqueuer, DataTable xnnode)
        {
            for (int i = 0; i < xnnode.Rows.Count; i++)
            {
                if (xnnode.Rows[i][0].ToString().Equals(dqueuer.Rows[0]["N_NODE_ID"].ToString()))
                {
                    noder.Rows.Add(xnnode.Rows[i].ItemArray);
                }
            }
        }

        /// <summary>
        /// 冒泡排序
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private DataTable maopao(DataTable dt)
        {
            for (int i = 0; i < dt.Rows.Count - 1; i++)
            {
                for (int j = 0; j < dt.Rows.Count - i - 1; j++)
                {
                    int k = Convert.ToInt32(dt.Rows[j]["N_QUEUE_NUMBER"].ToString());
                    int z = Convert.ToInt32(dt.Rows[j + 1]["N_QUEUE_NUMBER"].ToString());
                    if (k > z)
                    {
                        DataRow dr = dt.NewRow();
                        dr.ItemArray = dt.Rows[j].ItemArray;
                        dt.Rows[j].ItemArray = dt.Rows[j + 1].ItemArray;
                        dt.Rows[j + 1].ItemArray = dr.ItemArray;
                    }
                }
            }
            return dt;
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            if (Session["xndt"] != null)
            {
                Session["xndt"] = null;
                Session["xnqueue"] = null;
                Session["xndnode"] = null;
                Response.Redirect("SelectProcess.aspx");
            }
            else
            {
                Response.Redirect("SelectProcess.aspx");
            }
        }
    }
}